#include "GUIDataOutletWidget.h"
#include "ui_GUIDataOutletWidget.h"

#include "FITK_Interface/FITKInterfaceCustomData/FITKCDDataOutlet.h"
#include "FITK_Kernel/FITKCore/FITKOperatorRepo.h"
#include "OperatorsInterface/TreeEventOperator.h"

using namespace GUI;

GUIDataOutletWidget::GUIDataOutletWidget(Interface::FITKCDDataOutlet* obj, EventOper::ParaWidgetInterfaceOperator* oper, QWidget* parent) :
	GUIWidgetBase(parent), _oper(oper), _obj(obj)
{
	_ui = new Ui::GUIDataOutletWidget();
	_ui->setupUi(this);

	init();
}

GUIDataOutletWidget::~GUIDataOutletWidget()
{
	if (_ui) {
		delete _ui;
		_ui = nullptr;
	}
}

void GUIDataOutletWidget::init()
{
	setDataToWidget();
}

void GUIDataOutletWidget::setDataToWidget()
{
	_ui->lineEdit_Name->setText(_obj->getDataObjectName());
	_ui->doubleSpinBox_Minimum_xyz0->setValue(_obj->getMinimum_xyz()[0]);
	_ui->doubleSpinBox_Minimum_xyz1->setValue(_obj->getMinimum_xyz()[1]);
	_ui->doubleSpinBox_Minimum_xyz2->setValue(_obj->getMinimum_xyz()[2]);
	_ui->doubleSpinBox_Maximum_xyz0->setValue(_obj->getMaximum_xyz()[0]);
	_ui->doubleSpinBox_Maximum_xyz1->setValue(_obj->getMaximum_xyz()[1]);
	_ui->doubleSpinBox_Maximum_xyz2->setValue(_obj->getMaximum_xyz()[2]);
}


void GUIDataOutletWidget::on_lineEdit_Name_editingFinished()
{
	_obj->setDataObjectName(_ui->lineEdit_Name->text());

	auto treeOper = Core::FITKOperatorRepo::getInstance()->getOperatorT<EventOper::TreeEventOperator>("ModelTreeEvent");
	if (treeOper != nullptr)
	{
		treeOper->updateTree();
	}
}
void GUIDataOutletWidget::on_doubleSpinBox_Minimum_xyz0_valueChanged(double value)
{
	auto d = _obj->getMinimum_xyz();
	d[0] = value;
	_obj->setMinimum_xyz(d);
}
void GUIDataOutletWidget::on_doubleSpinBox_Minimum_xyz1_valueChanged(double value)
{
	auto d = _obj->getMinimum_xyz();
	d[1] = value;
	_obj->setMinimum_xyz(d);
}
void GUIDataOutletWidget::on_doubleSpinBox_Minimum_xyz2_valueChanged(double value)
{
	auto d = _obj->getMinimum_xyz();
	d[2] = value;
	_obj->setMinimum_xyz(d);
}
void GUIDataOutletWidget::on_doubleSpinBox_Maximum_xyz0_valueChanged(double value)
{
	auto d = _obj->getMaximum_xyz();
	d[0] = value;
	_obj->setMaximum_xyz(d);
}
void GUIDataOutletWidget::on_doubleSpinBox_Maximum_xyz1_valueChanged(double value)
{
	auto d = _obj->getMaximum_xyz();
	d[1] = value;
	_obj->setMaximum_xyz(d);
}
void GUIDataOutletWidget::on_doubleSpinBox_Maximum_xyz2_valueChanged(double value)
{
	auto d = _obj->getMaximum_xyz();
	d[2] = value;
	_obj->setMaximum_xyz(d);
}
